using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration ;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class JobSeekers_blocksearch : System.Web.UI.Page
{
    string alphabet = "";
    string connectionString = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        connectionString =
                         WebConfigurationManager.ConnectionStrings[
                           "RecruitVietnam"].ConnectionString;
        alphabet = Request.QueryString.Get("Alphabet");
        if (alphabet == null)
            alphabet = "";
        if (!IsPostBack)
            ShowData();

    }
    DataTable GetDataTable()
    {
        SqlServerProvider sqlServerProvider = new SqlServerProvider();
        sqlServerProvider.ConnectionString = connectionString;
        sqlServerProvider.CommandText =
        "SPCompanyByAlphabet";
        sqlServerProvider.ParameterCollection = new string[1] { "@Alphabet" };
        if (alphabet != "")
            sqlServerProvider.ValueCollection = new string[1] { alphabet + "%" };
        else
            sqlServerProvider.ValueCollection = new string[1] { alphabet };
        sqlServerProvider.CommandType = CommandType.StoredProcedure;
        DataTable dataTable = sqlServerProvider.GetDataTable();
        return dataTable;
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        ShowData();
        GridView1.PageIndex = e.NewPageIndex;
    }
    void ShowData()
    {
        GridViewHelper gridViewHelper = new GridViewHelper();
        gridViewHelper.FillDataTableToGridView(
        GetDataTable(),
        this.GridView1, 10, 10, PagerButtons.NumericFirstLast);
    }
    protected void btnBlock_Click(object sender, EventArgs e)
    {
        string insertQuery = "";
        foreach (GridViewRow gridViewRow in GridView1.Rows)
        {
            CheckBox checkBox = (CheckBox)
            gridViewRow.FindControl("chkID");
            if (checkBox.Checked)
            {
                try
                {
                    insertQuery += 
                    "insert into tblJSBlockSearchs("+
                    "UserID, RecruiterID) values(@UserID, " +
                    gridViewRow.Cells[1].Text + ")";
                }
                catch (Exception ex)
                {
                    literalError.Text = ex.Message;
                }
            }

        }
        if (insertQuery != "")
        {

            SqlServerProvider cls
             = new SqlServerProvider(connectionString);
            cls.CommandText = insertQuery;
            cls.ParameterCollection = 
            new string[1] { "@UserID" };
            cls.ValueCollection = new 
            string[1] { 
            Convert.ToString(Session["jsuserid"]) };
            if (cls.ExecuteNonQuery() > 0)
                Response.Redirect("blocksearchs.aspx");;            
        }
    }
    
}
